package com.insurance.modules.business.controller;

import java.util.Arrays;
import java.util.Map;

import com.insurance.entity.ProposalEntity;
import com.insurance.service.ProposalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.R;



/**
 * 投保单
 */
@RestController
@RequestMapping("proposal/proposal")
public class ProposalController {

    @Autowired
    private ProposalService proposalService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("proposal:proposal:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = proposalService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{proposalId}")
    @RequiresPermissions("proposal:proposal:info")
    public R info(@PathVariable("proposalId") String proposalId){
		ProposalEntity proposal = proposalService.getById(proposalId);
        return R.ok().put("proposal", proposal);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("proposal:proposal:save")
    public R save(@RequestBody ProposalEntity proposal){
		proposalService.save(proposal);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("proposal:proposal:update")
    public R update(@RequestBody ProposalEntity proposal){
		proposalService.updateById(proposal);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("proposal:proposal:delete")
    public R delete(@RequestBody String[] proposalIds){
		proposalService.removeByIds(Arrays.asList(proposalIds));
        return R.ok();
    }

}
